/**
 * 
 */
package jmine.tec.subscription.replicator;

import java.io.Serializable;

import jmine.tec.subscription.PublisherManager;
import jmine.tec.subscription.SubscriptionSettings;
import jmine.tec.subscription.impl.SubscriptionManagerImplementor;

import org.springframework.context.ApplicationEvent;

/**
 * Classe simples que encapsula uma publicacao parcial ou total
 * 
 * @author takeshi
 */
public abstract class AbstractPublicationWrapper extends ApplicationEvent implements Serializable {
    private static final long serialVersionUID = 748851857100757684L;

    private final SubscriptionSettings settings;

    private final String publisherIdentification;

    /**
     * C'tor
     * 
     * @param settings {@link SubscriptionSettings}
     * @param publisherIdentification {@link String}
     */
    public AbstractPublicationWrapper(SubscriptionSettings settings, String publisherIdentification) {
        super(publisherIdentification);
        this.publisherIdentification = publisherIdentification;
        this.settings = settings;
    }

    /**
     * Cuida da mensagem localmente. Encaminha a mensagem ao
     * {@link SubscriptionManagerImplementor#localPublish(jmine.tec.subscription.Publisher, SubscriptionSettings, jmine.tec.subscription.Publication)}
     * 
     * @param implementor {@link SubscriptionManagerImplementor}
     * @param publisherManager {@link PublisherManager}
     */
    public abstract void handleLocally(SubscriptionManagerImplementor implementor, PublisherManager publisherManager);

    /**
     * Cuida da mensagem. Encaminha a mensagem ao
     * {@link SubscriptionManagerImplementor#broadcast(jmine.tec.subscription.Publisher, SubscriptionSettings, jmine.tec.subscription.Publication)}
     * 
     * @param implementor {@link SubscriptionManagerImplementor}
     * @param publisherManager {@link PublisherManager}
     */
    public abstract void broadcast(SubscriptionManagerImplementor implementor, PublisherManager publisherManager);

    /**
     * @return {@link SubscriptionSettings}
     */
    protected final SubscriptionSettings getSettings() {
        return this.settings;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Object getSource() {
        return this.publisherIdentification;
    }

    /**
     * @return a identificacao do Publisher original
     */
    protected final String getPublisherIdentification() {
        return this.publisherIdentification;
    }

}